<?php


namespace App\Model;


class User extends Model
{

    protected $primaryKey = 'uid';
    protected $guarded = [];
    protected $hidden = ['password'];

    /**
     * 获取用户信息
     * @param $openid
     * @return \Hyperf\Database\Model\Builder|\Hyperf\Database\Model\Model|object|null
     */
    public static function getUserInfoByOpenid($openid)
    {
        return self::query()->where('openid', $openid)->first();
    }

    public static function getUserByUsername($username, $password = null)
    {
        $query = self::query();
        $query->where('username', $username);
        if ($password) $query->where('password', $password);
        return $query->first();
    }
}